#include "cafards.h"
#include <algorithm>
#include "fabriqueennemi.h"
#include "mygamescene.h"



void cafards::toucher(Projectile *P){

    hp = hp-std::max((float)0, (P->getFrappe() - resist));
    qDebug()<<hp;
    if (hp<=0){
        if(taille>2){
            int rot=rotation();
            if(rot==0 || rot==180)
            {
                Ennemis* e1 = FabriqueEnnemi::methodeFabrication("cafard",taille-1,x()+0.5*600.0/16+11,y()+600.0/16,rot);
                Ennemis* e2 = FabriqueEnnemi::methodeFabrication("cafard",taille-1,x()+0.5*600.0/16-11,y()+600.0/16,rot);
                MyGameScene::getMyScene()->addItem(e1);
                MyGameScene::getMyScene()->addItem(e2);
                MyGameScene::getMyScene()->ajoutEnnemis(e1);
                MyGameScene::getMyScene()->ajoutEnnemis(e2);


            }
            else
            {
                Ennemis* e1 = FabriqueEnnemi::methodeFabrication("cafard",taille-1,x()+0.5*600.0/16,y()+600.0/16+11,rot);
                Ennemis* e2 = FabriqueEnnemi::methodeFabrication("cafard",taille-1,x()+0.5*600.0/16,y()+600.0/16-11,rot);
                MyGameScene::getMyScene()->addItem(e1);
                MyGameScene::getMyScene()->addItem(e2);
                MyGameScene::getMyScene()->ajoutEnnemis(e1);
                MyGameScene::getMyScene()->ajoutEnnemis(e2);
            }
        }
        mort=true;
        monimage1.load("boum.gif");
        monimage=&monimage1;
    }
}

void cafards::advance(int i){
    if(i==1){
        if(!mort)
        {
            this->changerImage();
            this->deplacer();
        }
    }

}
